<?php

namespace app\api\controller;


use app\common\controller\Api;
use app\model\Admin;

use app\model\User;
/**
 * 首页接口
 */
class Package extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function getItem()
    {
        $package_id = input('package_id',0);
        if(empty($package_id)){
            $package = db('package')->where('status',1)->find();
        }else{
            $package = db('package')->where('id',$package_id)->find();
        }
        if(empty($package)){
            $this->error("暂无记录");
        }
        $package_id = $package['id'];
        $itemData = db('package_item')->where('package_id',$package_id)->order('sort desc')->select();
        foreach ($itemData as $key=>&$one){
            $one['has_choose'] = -1;
            if($key == 0){
                $one['has_choose'] = 1;
            }
            $one['avg_money'] = sprintf("%.2f",$one['money']/$one['num']);
            if($key <=1){
                $one['tip'] = "限时特惠";
            }else{
                $yuan_money = round($one['money']/0.8);
                $one['tip'] = "原价{$yuan_money}元，享8折";
            }
        }
        $this->success('请求成功',$itemData);
    }



}
